Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports ClubStarterKit.Web

Partial Class Poll_Answers
    Inherits System.Web.UI.Page

    Private _pollId As Guid

    Public Property PollId() As Guid
        Get
            If _pollId = Guid.Empty Then
                _pollId = DirectCast(ViewState("PollId"), Guid)
            End If
            Return _pollId
        End Get
        Set(ByVal value As Guid)
            ViewState("PollId") = value
        End Set
    End Property


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            PollId = New Guid(Request("PollId"))
        Catch
            Response.Redirect("~/Poll/Manage.aspx", True)
        End Try
        If PollId = Guid.Empty Then
            Response.Redirect("~/Poll/Manage.aspx", True)
        End If

        Dim q As New PollQuestion()
        q = ClubStarterKit.Web.Poll.LoadQuestion(PollId)
        QuestionLabel.Text = q.Question

        'PollCrumb
        PollCrumb.NavigateUrl = "~/Poll/Manage.aspx?PollId=" + q.PollId.ToString()
        PollCrumb.Text = q.Question
    End Sub

    Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs)
        If e.Values("PollAnswerId") Is Nothing Then
            e.Values("PollAnswerId") = Guid.NewGuid()
        End If

        If String.IsNullOrEmpty(e.Values("Answer").ToString()) Then
            e.Values("Answer") = "*I FORGOT TO PUT IN AN ANSWER*"
        End If

        If e.Values("Rank") Is Nothing Then
            e.Values("Rank") = 10
        End If

        If e.Values("QuestionId") Is Nothing Then
            e.Values("QuestionId") = PollId
        End If
    End Sub

    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
        If String.IsNullOrEmpty(e.NewValues("Answer").ToString()) Then
            e.NewValues("Answer") = "*I FORGOT TO PUT IN AN ANSWER*"
        End If

        If e.NewValues("Rank") Is Nothing Then
            e.NewValues("Rank") = 10
        End If
    End Sub
End Class
